home *** CD-ROM | disk | FTP | other *** search
/ An Introduction to Progr…l Basic 6.0 (4th Edition) / An Introduction to Programming using Visual Basic 6.0.iso / PROGRAMS / CH7 / 7-4-6.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-11-02  |  3.7 KB  |  120 lines

  1. VERSION 5.00
  2. Begin VB.Form frn7_4_6 
  3.    Caption         =   "Metropolitan Statistics"
  4.    ClientHeight    =   1890
  5.    ClientLeft      =   915
  6.    ClientTop       =   1980
  7.    ClientWidth     =   6855
  8.    BeginProperty Font 
  9.       Name            =   "MS Sans Serif"
  10.       Size            =   8.25
  11.       Charset         =   0
  12.       Weight          =   700
  13.       Underline       =   0   'False
  14.       Italic          =   0   'False
  15.       Strikethrough   =   0   'False
  16.    EndProperty
  17.    LinkTopic       =   "Form1"
  18.    PaletteMode     =   1  'UseZOrder
  19.    ScaleHeight     =   1890
  20.    ScaleWidth      =   6855
  21.    Begin VB.PictureBox picResult 
  22.       Height          =   1215
  23.       Left            =   120
  24.       ScaleHeight     =   1155
  25.       ScaleWidth      =   6555
  26.       TabIndex        =   3
  27.       Top             =   600
  28.       Width           =   6612
  29.    End
  30.    Begin VB.CommandButton cmdDisplayStats 
  31.       Caption         =   "Display City Stats"
  32.       Default         =   -1  'True
  33.       Height          =   375
  34.       Left            =   4200
  35.       TabIndex        =   2
  36.       Top             =   120
  37.       Width           =   1815
  38.    End
  39.    Begin VB.TextBox txtCity 
  40.       Height          =   285
  41.       Left            =   2160
  42.       TabIndex        =   1
  43.       Top             =   240
  44.       Width           =   1335
  45.    End
  46.    Begin VB.Label lblName 
  47.       Caption         =   "Name of city:"
  48.       Height          =   255
  49.       Left            =   960
  50.       TabIndex        =   0
  51.       Top             =   240
  52.       Width           =   1215
  53.    End
  54. Attribute VB_Name = "frn7_4_6"
  55. Attribute VB_GlobalNameSpace = False
  56. Attribute VB_Creatable = False
  57. Attribute VB_PredeclaredId = True
  58. Attribute VB_Exposed = False
  59. Dim city(1 To 10) As String, pop(1 To 10) As Single, income(1 To 10) As Single
  60. Dim natives(1 To 10) As Single, advDeg(1 To 10) As Single
  61. Private Sub cmdDisplayStats_Click()
  62.   Dim searchCity As String, result As Integer
  63.   'Search for city in the metropolitan areas table
  64.   Call GetCityName(searchCity)
  65.   Call FindCity(searchCity, result)
  66.   picResult.Cls
  67.   If result > 0 Then
  68.       Call ShowData(result)
  69.     Else
  70.       picResult.Print searchCity & " not in file"
  71.   End If
  72. End Sub
  73. Private Sub FindCity(searchCity As String, result As Integer)
  74.   Dim first As Integer, middle As Integer, last As Integer
  75.   Dim foundFlag As Boolean
  76.   'Binary search table for city name
  77.   first = 1
  78.   last = 10
  79.   foundFlag = False
  80.   Do While (first <= last) And (foundFlag = False)
  81.     middle = Int((first + last) / 2)
  82.     Select Case UCase(city(middle))
  83.       Case searchCity
  84.         foundFlag = True
  85.       Case Is > searchCity
  86.         last = middle - 1
  87.       Case Is < searchCity
  88.         first = middle + 1
  89.     End Select
  90.   Loop
  91.   If foundFlag Then
  92.       result = middle
  93.     Else
  94.       result = 0
  95.   End If
  96. End Sub
  97. Private Sub Form_Load()
  98.   Dim j As Integer
  99.   'Assume that the data for city name, population, medium income, % native,
  100.   'and % advanced degree have been placed in the file "CITYSTAT.TXT"
  101.   '(First line of file is "Boston", 4.2, 4066, 73, 12)
  102.   Open App.Path & "\CITYSTAT.TXT" For Input As #1
  103.   For j = 1 To 10
  104.     Input #1, city(j), pop(j), income(j), natives(j), advDeg(j)
  105.   Next j
  106.   Close #1
  107. End Sub
  108. Private Sub GetCityName(searchCity As String)
  109.   'Request name of city as input
  110.   searchCity = UCase(Trim(txtCity.Text))
  111. End Sub
  112. Private Sub ShowData(index As Integer)
  113.   'Display city and associated information
  114.   picResult.Print , "Pop. in", "Med. income", "% Native", "% Advanced"
  115.   picResult.Print "Metro Area", "millions", "per hsd", "to State", "Degree"
  116.   picResult.Print
  117.   picResult.Print city(index); Tab(16); pop(index), income(index),
  118.   picResult.Print natives(index), advDeg(index)
  119. End Sub
  120.